<?php

include_once($_SERVER['DOCUMENT_ROOT'].'/bs/include/header.inc');
include_once($_SERVER['DOCUMENT_ROOT'].'/bs/include/comp.inc');
include_once($_SERVER['DOCUMENT_ROOT'].'/bs/include/fcs.php');
?>


<?php

if(isset($_GET['task']))
{
		if(!$link=mysql_connect("localhost",$user,$pass))
			die("Error in Database Connection");

		if(!mysql_select_db("bs"))
			echo("Error in Database Selection");

		if($_GET['task']=="displayform")
		{
				$fromdate="01-".date("m-Y");
				$todate="31-".date("m-Y");
				$arr=explode("-",$todate);
			
				while(!checkdate($arr[1],$arr[0],$arr[2]))
				{
						$arr[0]=$arr[0]-1;
				}
				$todate=$arr[0]."-".$arr[1]."-".$arr[2];
			
?>

				| <a href="trial_balance.php?task=displayform">BS Summary</a> </div>
				<h3>Select Date Range</h3>
				<table cellpadding="3" class="list">
				<form name="displayform" action="<?php echo $_SERVER['PHP_SELF']?>" method="get">
				<tr><td><label>From </label></td><td> <input type="text" name="fromdate" size="12" value="<?php echo $fromdate; ?>" /></td></tr>
				<tr><td><label>To </label></td><td> <input type="text" name="todate" size="12" value="<?php echo $todate; ?>" /></td></tr>
				
				<tr><td align="center"><input type="submit" value="Display" align="absmiddle" /></td></tr>
				<input type="hidden" name="task" value="display" />
				</form>
				</table>
			
		
<?php
		}//END OF TASK=DISPLAY FORM
		if($_GET['task']=="display")
		{
				$valid=1;
				echo "	| <a href='trial_balance.php?task=displayform'>BS Summary</a> </div> ";
				
				//VALIDATING DATEs
				
				if(!ereg("^[0-3]?[0-9][\./\-][0-1]?[0-9][\-]20[0-9][0-9]$",$_GET['fromdate'])) 
				{
						echo "Check Your Input 'From' Date<br>";
						$valid=0;
				}
				else
				{
					$datearr=explode("-",$_GET['fromdate']);
					if(!checkdate($datearr[1],$datearr[0],$datearr[2]))
					{
							echo "Check Your Input 'From' Date<br>";
							$valid=0;
					}
					else
							$fromdate=date("Y-m-d",mktime(0,0,0,$datearr[1],$datearr[0],$datearr[2]));
				}
				
				
				if(!ereg("^[0-3]?[0-9][\./\-][0-1]?[0-9][\-]20[0-9][0-9]$",$_GET['todate'])) 
				{
						echo "Check Your Input 'To' Date<br>";
						$valid=0;
				}
				else
				{
					$datearr=explode("-",$_GET['todate']);
					if(!checkdate($datearr[1],$datearr[0],$datearr[2]))
					{
							echo "Check Your Input 'To' Date<br>";
							$valid=0;
					}
					else
							$todate=date("Y-m-d",mktime(0,0,0,$datearr[1],$datearr[0],$datearr[2]));
				}
				
				
				if(!isset($_GET['group_id']))
						$group_id='00';
				else
						$group_id=$_GET['group_id'];

				$result=mysql_query("select gpname,id,under from bs_groups where id='{$group_id}'");
						if(!$result)
				echo "error";
						$arr=mysql_fetch_array($result);

				if($group_id=='00')
						echo"<h3>Trial Balance From <font color='#FF6600'>{$_GET['fromdate']}</font> To <font color='#FF6600'>{$_GET['todate']}</font></h3>";	
				else
						echo"<h3>{$arr['gpname']} From <font color='#FF6600'>{$_GET['fromdate']}</font> To <font color='#FF6600'>{$_GET['todate']}</font></h3>";	
				if($group_id!='00')
						echo "<div class='trial_list'><a href='trial_balance.php?fromdate={$_GET['fromdate']}&todate={$_GET['todate']}&task=display&group_id={$arr['under']}'><--</a></div>";
				global $pandl,$diffopb;
				$pandl=0;
				$diffopb=0;
				display_trial_balance_of($group_id);


		
		
		}//END OF TASK=DISPLAY
}//END OF ISSET GET


?>
